import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import gamma

# 从参数为1的伽马分布生成1000个随机数
data = np.random.gamma(1, size=1000)

# 绘制直方图
plt.hist(data, bins=30, density=True, alpha=0.6, color='g', label='Histogram of Samples')

# 绘制伽马分布的概率密度函数
x = np.linspace(0, 10, 1000)
pdf = gamma.pdf(x, 1)
plt.plot(x, pdf, 'r-', lw=2, label='Gamma PDF')

# 添加图例和标签
plt.legend()
plt.xlabel('Value')
plt.ylabel('Probability Density')
plt.title('Gamma Distribution with Parameter 1')
plt.show()